//
//  MessageModel.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/25.
//

#import "MessageModel.h"
#import "CommonUtil.h"
@implementation MessageModel

-(instancetype)init{
    if (self = [super init]) {
        self.imageWH = AD(80);
    }
    return self;
}


-(CGFloat)replayCellHeight{
    CGFloat h = AD(30);
    CGFloat replayViewW = SCREEN_WIDTH-AD(100);
    CGFloat contentLabelLeft = AD(20) + AD(30) + AD(20);
    if (self.replayYourSelf) {
    }else{
        CGFloat contentW = [CommonUtil countWidth:self.replayOtherName font:[UIFont systemFontOfSize:AD(13)] height:AD(15)];
        contentLabelLeft = contentLabelLeft + contentW;
    }
    CGFloat contentW = replayViewW - contentLabelLeft;
    CGFloat contentH = [CommonUtil countHeight:self.replayContent font:[UIFont systemFontOfSize:AD(14)] width:contentW];
    h = h + contentH;
    return h;
}


-(CGFloat)feedHeight{
    if (_feedHeight > 0) {
        return _feedHeight;
    }
    CGFloat h = 0;
    //文字
    CGFloat labelH = [CommonUtil countHeight:self.content
                                        font:[UIFont systemFontOfSize:AD(13)]
                                       width:SCREEN_WIDTH-AD(140)];
    h = h + labelH;
    // 图片区域
    CGFloat imageAreaH = 0;
    for (NSInteger i = 0; i < self.imageCount; i++) {
        CGFloat y =  AD(10) + ((i/3) * (self.imageWH + AD(10)));
        imageAreaH = y + self.imageWH;
    }
    h = h + imageAreaH;
    

    
    if (!_isDetail) {
        // 回复按钮
        h = h + AD(7) + AD(20);
    }
    return h;
}

-(CGFloat)cellHeight{
    if (_cellHeight > 0) {
        return _cellHeight;
    }
    // 人物信息区域
    CGFloat h = AD(20+40); //infoview
    h = h + self.feedHeight;
    
    // 回复内容区域
    if (self.replayList.count > 0) {
        h = h + AD(15) + self.replayHeight ;
    }
    // 底部间隔
    h = h + AD(15);
    return h;
}

-(CGFloat)replayHeight{
    
    if (self.replayList.count == 0) {
        return 0;
    }
    
    CGFloat h = 0;
    for (NSInteger i = 0; i < self.replayList.count; i++) {
        if (i < 3) {
            MessageModel *model = self.replayList[i];
            h = h + model.replayCellHeight;
        }
    }
    h = h + AD(25);
    return h;
}

-(void)addReayTest{
    MessageModel *replay1 = [[MessageModel alloc] init];
    replay1.replayContent = @"第一代iPhone于2007年1月9日由苹果公司前首席执行官史蒂夫·乔布斯发布";
    replay1.replayName = @"非凡小鱼1";
    replay1.replayYourSelf = YES;
    
    MessageModel *replay2 = [[MessageModel alloc] init];
    replay2.replayContent = @"第二代iPhone 4s于2011年10月04日在美国加利福尼亚州举行的Let's ...";
    replay2.replayName = @"非凡小鱼2";
    replay2.replayOtherName = @"天亮";
    replay2.replayYourSelf = false;
    
    MessageModel *replay3 = [[MessageModel alloc] init];
    replay3.replayContent = @"第三代iPhone 4s于2011年10月04日在美国加利福尼亚州举行的Let's ...";
    replay3.replayName = @"非凡小鱼3";
    replay3.replayYourSelf = YES;
    
    MessageModel *replay4 = [[MessageModel alloc] init];
    replay4.replayContent = @"第4代iPhone 4s于2011年10月04日在美国加利福尼亚州举行的Let's ...";
    replay4.replayName = @"非凡小鱼4";
    replay4.replayYourSelf = YES;
    
    self.replayList = @[replay1,replay2,replay3,replay4];
    self.replayHeight = AD(200);
}

@end
